<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="58px">
      <el-form-item label="姓名" prop="staffName">
        <el-input
          v-model="queryParams.staffName"
          placeholder="请输入员工姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证" prop="idCard">
        <el-input
          v-model="queryParams.idCard"
          placeholder="请输入身份证编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="开始" prop="startDate">
        <el-date-picker
          v-model="queryParams.startDate"
          size="small"
          style="width: 200px"
          value-format="yyyy-MM-dd"
          type="date"
          range-separator="-"
          placeholder="选择日期"
        ></el-date-picker>
      </el-form-item>
        <el-form-item label="结束" prop="endDate">
          <el-date-picker
            v-model="queryParams.endDate"
            size="small"
            style="width: 200px"
            value-format="yyyy-MM-dd"
            type="date"
            range-separator="-"
            placeholder="选择日期"
          ></el-date-picker>

        </el-form-item>



      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">



      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['job:trafficRecord:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="recordList" >

      <el-table-column label="员工姓名" align="center" prop="staffName" />
      <el-table-column label="身份证编码" align="center" prop="idCard" />
      <el-table-column label="通行时间" align="center" prop="dateTime" />
      <el-table-column label="设备号" align="center" prop="deviceNo" />
      <el-table-column label="最后记录" align="center" prop="latsNum" />


    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改长期工通行记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="员工姓名" prop="staffName">
          <el-input v-model="form.staffName" placeholder="请输入员工姓名" />
        </el-form-item>
        <el-form-item label="身份证编码" prop="idCard">
          <el-input v-model="form.idCard" placeholder="请输入身份证编码" />
        </el-form-item>
        <el-form-item label="部门名称" prop="deptName">
          <el-input v-model="form.deptName" placeholder="请输入部门名称" />
        </el-form-item>
        <el-form-item label="通行门点" prop="address">
          <el-input v-model="form.address" placeholder="请输入通行门点" />
        </el-form-item>
        <el-form-item label="出人类型 1-入口 2-出口" prop="passType">
          <el-select v-model="form.passType" placeholder="请选择出人类型 1-入口 2-出口">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="通行时间" prop="dateTime">
          <el-input v-model="form.dateTime" placeholder="请输入通行时间" />
        </el-form-item>
        <el-form-item label="用户编号" prop="userCode">
          <el-input v-model="form.userCode" placeholder="请输入用户编号" />
        </el-form-item>
        <el-form-item label="考勤机里的最大记录" prop="latsNum">
          <el-input v-model="form.latsNum" placeholder="请输入考勤机里的最大记录" />
        </el-form-item>
        <el-form-item label="设备号" prop="deviceNo">
          <el-input v-model="form.deviceNo" placeholder="请输入设备号" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRecord, getRecord, delRecord, addRecord, updateRecord, exportRecord } from "@/api/job/trafficRecord/trafficRecord";

export default {
  name: "trafficRecord",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 长期工通行记录表格数据
      recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        staffName: null,
        idCard: null,
        startDate: null,
        endDate: null,
        latsNum: null,
        deviceNo: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询长期工通行记录列表 */
    getList() {
      this.loading = true;
      listRecord(this.queryParams).then(response => {
        this.recordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        staffName: null,
        idCard: null,
        deptName: null,
        address: null,
        passType: null,
        dateTime: null,
        userCode: null,
        createTime: null,
        latsNum: null,
        deviceNo: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.staffName)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },



    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有长期工通行记录数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.exportLoading = true;
        return exportRecord(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>
